package action;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.security.AccessControlContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Test {
    public static void main(String[] args) throws SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        ComboPooledDataSource comboPooledDataSource = (ComboPooledDataSource)ac.getBean("jdbc1");

        Connection connection = comboPooledDataSource.getConnection();
//        System.out.println(comboPooledDataSource.getDriverClass());
//        System.out.println(comboPooledDataSource.getJdbcUrl());
//        System.out.println(comboPooledDataSource.getUser());
//        System.out.println(comboPooledDataSource.getPassword());
        PreparedStatement preparedStatement = connection.prepareStatement("select * from zz");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()){
            System.out.println(  resultSet.getString("id") );
            System.out.println(  resultSet.getString("name") );
        }
        resultSet.close();
        preparedStatement.close();
        System.out.println(connection);
        connection.close();
    }
}
